namespace IAM.Interface.Common.XMLResolution
{
    using IAM.Interface.Common.Abnormity;
    using IAM.Interface.Model;
    using IAM.Interface.Model.ENUM;
    using System;
    using System.Text;
    using System.Xml;

    public class Response : AbstractXMLResolution
    {
        private IAM.Interface.Model.ENUM.ActionType _actintype;
        private ResponseException _exception;
        private string _transactionid;

        public Response(IAM.Interface.Model.ENUM.ActionType actintype)
        {
            this._actintype = IAM.Interface.Model.ENUM.ActionType.Nullity;
            this._exception = null;
            this._transactionid = "";
            this._actintype = actintype;
        }

        public Response(IAM.Interface.Model.ENUM.ActionType actintype, ResponseException exception)
        {
            this._actintype = IAM.Interface.Model.ENUM.ActionType.Nullity;
            this._exception = null;
            this._transactionid = "";
            this._actintype = actintype;
            this._exception = exception;
        }

        public Response(IAM.Interface.Model.ENUM.ActionType actintype, string transactionid)
        {
            this._actintype = IAM.Interface.Model.ENUM.ActionType.Nullity;
            this._exception = null;
            this._transactionid = "";
            this._actintype = actintype;
            this._transactionid = transactionid;
        }

        public Response(IAM.Interface.Model.ENUM.ActionType actintype, ResponseException exception, string transactionid)
        {
            this._actintype = IAM.Interface.Model.ENUM.ActionType.Nullity;
            this._exception = null;
            this._transactionid = "";
            this._actintype = actintype;
            this._exception = exception;
            this._transactionid = transactionid;
        }

        public override XmlNode GetCurrentNode()
        {
            XmlElement xe = base.XmlDocument.DocumentElement;
            switch (this.ActionType)
            {
                case IAM.Interface.Model.ENUM.ActionType.IDEN_MANAGE:
                    return xe.SelectSingleNode("AccountInfo");

                case IAM.Interface.Model.ENUM.ActionType.IDEN_GETACMODEL:
                    return xe.SelectSingleNode("ACMMode");

                case IAM.Interface.Model.ENUM.ActionType.IDEN_GETUSERACI:
                    return xe;

                case IAM.Interface.Model.ENUM.ActionType.IDEN_SETUSERACI:
                    return xe;

                case IAM.Interface.Model.ENUM.ActionType.ORG_UPDATE:
                    return xe;

                case IAM.Interface.Model.ENUM.ActionType.ORG_CREATE:
                    return xe;

                case IAM.Interface.Model.ENUM.ActionType.ORG_DELETE:
                    return xe;

                case IAM.Interface.Model.ENUM.ActionType.DM_GETMODULELIST:
                    return xe.SelectSingleNode("Modules");

                case IAM.Interface.Model.ENUM.ActionType.DM_GETDELEINFO:
                    return xe;

                case IAM.Interface.Model.ENUM.ActionType.DM_SETDELEINFO:
                    return xe;
            }
            return null;
        }

        public override string GetWholeXML()
        {
            ResponseData responsedata = new ResponseData();
            responsedata.TransactionID = this.TransactionID;
            responsedata.ResponseTime = DateTime.Now;
            responsedata.StatusCode = this.Exception.StatusCode;
            if (this.Exception.StatusCode == 200)
            {
                responsedata.ReturnMessage = "OK";
            }
            else
            {
                responsedata.ReturnMessage = "Error";
            }
            StringBuilder xml = new StringBuilder();
            xml.Append(responsedata.XMLBoday);
            xml.Append(this.Result.XML);
            if ((this.Exception != null) && (this.Exception.StatusCode == 200))
            {
                xml.Append(base.XmlInfo);
            }
            xml.Append(responsedata.XMLFinis);
            return xml.ToString();
        }

        public IAM.Interface.Model.ENUM.ActionType ActionType
        {
            get
            {
                return this._actintype;
            }
            set
            {
                this._actintype = value;
            }
        }

        public ResponseException Exception
        {
            get
            {
                return this._exception;
            }
            set
            {
                this._exception = value;
            }
        }

        public IAM.Interface.Model.Result Result
        {
            get
            {
                if (this.Exception == null)
                {
                    throw new System.Exception("No setting Exception");
                }
                IAM.Interface.Model.Result result = new IAM.Interface.Model.Result();
                result.ErrorCode = Convert.ToString(this.Exception.StatusCode);
                result.ErrorMessage = this.Exception.Message;
                return result;
            }
        }

        public string TransactionID
        {
            get
            {
                return this._transactionid;
            }
            set
            {
                this._transactionid = value;
            }
        }
    }
}
